#include "WatchDogTimer.h"
#include "../../../bit/bit.h"


void WatchDogTimer::setWatchdogTurnOffEnable(unsigned char flag)
{
	WDTCR = SetBit(WDTCR, WDTOE, flag);
}

void WatchDogTimer::setEnable(unsigned char flag)
{
	WDTCR = SetBit(WDTCR, WDE, flag);
}


void WatchDogTimer::setPrescaler(unsigned char flag)
{
	switch(flag)
	{
	case Prescaler16K_Watchdog:
		WDTCR = SetBit(WDTCR, WDP0, 0);
		WDTCR = SetBit(WDTCR, WDP1, 0);
		WDTCR = SetBit(WDTCR, WDP2, 0);
		break;
	case Prescaler32K_Watchdog:
		WDTCR = SetBit(WDTCR, WDP0, 1);
		WDTCR = SetBit(WDTCR, WDP1, 0);
		WDTCR = SetBit(WDTCR, WDP2, 0);
		break;
	case Prescaler64K_Watchdog:
		WDTCR = SetBit(WDTCR, WDP0, 0);
		WDTCR = SetBit(WDTCR, WDP1, 1);
		WDTCR = SetBit(WDTCR, WDP2, 0);
		break;
	case Prescaler128K_Watchdog:
		WDTCR = SetBit(WDTCR, WDP0, 1);
		WDTCR = SetBit(WDTCR, WDP1, 1);
		WDTCR = SetBit(WDTCR, WDP2, 0);
		break;
	case Prescaler256K_Watchdog:
		WDTCR = SetBit(WDTCR, WDP0, 0);
		WDTCR = SetBit(WDTCR, WDP1, 0);
		WDTCR = SetBit(WDTCR, WDP2, 1);
		break;
	case Prescaler512K_Watchdog:
		WDTCR = SetBit(WDTCR, WDP0, 1);
		WDTCR = SetBit(WDTCR, WDP1, 0);
		WDTCR = SetBit(WDTCR, WDP2, 1);
		break;
	case Prescaler1024K_Watchdog:
		WDTCR = SetBit(WDTCR, WDP0, 0);
		WDTCR = SetBit(WDTCR, WDP1, 1);
		WDTCR = SetBit(WDTCR, WDP2, 1);
		break;
	case Prescaler2048K_Watchdog:
		WDTCR = SetBit(WDTCR, WDP0, 1);
		WDTCR = SetBit(WDTCR, WDP1, 1);
		WDTCR = SetBit(WDTCR, WDP2, 1);
		break;
	default:
		WDTCR = SetBit(WDTCR, WDP0, 0);
		WDTCR = SetBit(WDTCR, WDP1, 0);
		WDTCR = SetBit(WDTCR, WDP2, 0);
		break;
	}
}

